package com.hci.mercatinidinatale;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity implements View.OnClickListener
{

	Button btnLeggiQRCode;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Button btnRicercaMercatino = (Button)findViewById(R.id.btnRicercaMercatino);
		btnLeggiQRCode = (Button)findViewById(R.id.btnLeggiQRCode);
		
		btnRicercaMercatino.setOnClickListener(this);
		btnLeggiQRCode.setOnClickListener(this);
		
		Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/AbyssinicaSIL-R.ttf");
		TextView tv =(TextView)findViewById(R.id.txtTitle);
		tv.setTypeface(tf);
	}

	@Override
	public void onClick(View v)
	{
		if (v.getId() == (R.id.btnRicercaMercatino))
		{
			Intent i = new Intent(this, RicercaMercatino.class);
			startActivity(i);
		} else if (v.getId() == (R.id.btnLeggiQRCode))
		{
			
			Intent i = new Intent("com.google.zxing.client.android.SCAN");
			i.putExtra("SCAN_MODE", "QR_CODE_MODE");
			startActivityForResult(i, 0);
			
		}
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent intent)
	{
		if (requestCode == 0) {
            
            if (resultCode == RESULT_OK)
            {
            	startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra("SCAN_RESULT"))));
            } 
            else if (resultCode == RESULT_CANCELED)
            {
            
            }
        }
		 
	}
	
}
